﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="OppertunityActions.aspx.cs"
    Inherits="iGRID_Ooredoo_SPCRM_My_Opportunities.Layouts.iGRID_Ooredoo_SPCRM_My_Opportunities.OpportunityActions"
    DynamicMasterPageFile="~masterurl/default.master" %>




<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
    <link rel="Stylesheet" type="text/css" href="/_layouts/1033/STYLES/Themable/FORMS.CSS" />
    <style type="text/css">
        .gridpager table
        {
            float: right;
        }
    </style>
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <br />
    <div>
        <table cellpadding="0" cellspacing="0" width="100%" class="tbl-default">
            <tr>
                <td colspan="4" class="formtitle">
                    Opportunity Actions
                </td>
            </tr>
        </table>
    </div>
    <br />
    <div id="divAppPage" runat="server" visible="false">
        <table align="center" cellpadding="0" cellspacing="0" width="100%" class="tbl-default">
            <tr>
                <td >
                    <asp:Label ID="lblEnquiryId" runat="server" Height="100%" Text="Opportunity Id" Width="100%"></asp:Label>
                </td>
                <td style="padding-left:10px">
                    <asp:Label ID="lblEnquiryIdShow" runat="server" Height="100%" Text="" Width="100%"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblEnquiryTitle" runat="server" Height="100%" Text="Opportunity Title"
                        Width="100%"></asp:Label>
                </td>
                <td style="padding-left:10px">
                    <asp:Label ID="lblEnquiryTitleShow" runat="server" Height="100%" Text="" Width="100%"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblStDate" runat="server" Height="100%" Text="Start Date" Width="100%"></asp:Label>
                </td>
                <td class="removeborder">
                    <SharePoint:DateTimeControl ID="dtActStDate" runat="server" LocaleId="2057" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblEndDate" runat="server" Height="100%" Text="End Date" Width="100%"></asp:Label>
                </td>
                <td class="removeborder">
                    <SharePoint:DateTimeControl ID="dtActEndDate" runat="server" LocaleId="2057" />
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblActionType" runat="server" Height="100%" Text="Action Type" Width="100%"></asp:Label>
                </td>
                <td style="padding-left:10px">
                    <%--<asp:TextBox ID="txtActionType" runat="server" Height="100%" Width="29%"></asp:TextBox>--%>
                    <asp:DropDownList ID="ddlActionTypes" runat="server" AutoPostBack="false">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblRemarks" runat="server" Height="100%" Text="Remarks" Width="100%"></asp:Label>
                </td>
                <td style="padding-left:10px">
                    <asp:TextBox ID="txtRemarks" runat="server" Height="100%" Rows="4" TextMode="MultiLine"
                        class="ms-long ms-spellcheck-true" Width="100%"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CssClass="ms-ButtonHeightWidth"
                        OnClientClick="javascript:return ValidateHourMinute();" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click"
                        CssClass="ms-ButtonHeightWidth" CausesValidation="false" />
                </td>
            </tr>
        </table>
    </div>
    <br />
    <div id="divError" runat="server" style="text-align: center; width: 100%">
        <asp:Label ID="lblEmptyText" runat="server" Text="There are no items to show." CssClass="error-alt"></asp:Label>
        <asp:Button runat="server" ID="btnClose" Text="Close" OnClick="btnCancel_Click" CssClass="ms-ButtonHeightWidth" />
    </div>
    <%--<div id="div1" runat="server" style="text-align: center; width: 100%">
        <asp:Label ID="lblError" runat="server" CssClass="error-alt"></asp:Label>
    </div>--%>
    <br />
    <asp:HiddenField ID="hdnSiteURL" runat="server" Value="" />
    <div id="divGv" runat="server" visible="false" style="border-spacing: 10px">
        <asp:GridView ID="gvEnquiryActions" runat="server" AutoGenerateColumns="False" Width="100%"
            EnableModelValidation="True" OnRowEditing="gvEnquiryActions_RowEditing" OnRowDeleting="gvEnquiryActions_RowDeleting"
            OnPageIndexChanging="gvEnquiryActions_PageIndexChanging" AllowPaging="true" PageSize="5"
            CellPadding="0" CellSpacing="0" GridLines="None" CssClass="tbl-default" AlternatingRowStyle-CssClass="alt-tr">
            <Columns>
                <asp:TemplateField Visible="false">
                    <ItemTemplate>
                        <asp:HiddenField ID="hdnid" runat="server" Value='<%# Eval("ID") %>' Visible="false" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="S.No">
                    <ItemTemplate>
                        <asp:Label ID="lblSNo" runat="server" Text='<%# Container.DataItemIndex+1 %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Title" HeaderText="Opportunity Title" SortExpression="Opportunity Id"
                    ReadOnly="true" />
                <asp:TemplateField HeaderText="Opportunity Id">
                    <ItemTemplate>
                        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("OpportunityID","/_layouts/iGRID_Ooredoo_SPCRM_Opportunity_Forms/Opportunity_General_Data.aspx?Mode=View&OppID={0}") %>'
                            Text='<%# Eval("OpportunityID") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Start Date" HeaderText="Action Start Date" SortExpression="Action Start Date"
                    ReadOnly="true" />
                <asp:BoundField DataField="End Date" HeaderText="Action End Date" SortExpression="Action End Date"
                    ReadOnly="true" />
                <asp:BoundField DataField="Action Type" HeaderText="Action Type" SortExpression="Action Type"
                    ReadOnly="true" />
                <asp:BoundField DataField="Remarks" HeaderText="Remarks" SortExpression="Remarks"
                    ReadOnly="true" />
                <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" ReadOnly="true"
                    Visible="false" />
                <asp:CommandField HeaderText="Actions" InsertVisible="False" ButtonType="Image" ShowCancelButton="False"
                    ShowDeleteButton="True" ShowEditButton="True" EditImageUrl="~/_layouts/1033/IMAGES/edit-icon.png"
                    DeleteImageUrl="~/_layouts/1033/IMAGES/delete.png" />
            </Columns>
            <PagerSettings FirstPageText="First Page" LastPageText="Last Page" Mode="NumericFirstLast"
                Position="Bottom" />
            <PagerStyle BackColor="Lavender" ForeColor="LightSlateGray" HorizontalAlign="Center" />
        </asp:GridView>
    </div>
    <br />
    <script language="javascript" type="text/javascript">


        function isEmpty(obj) {
            if (typeof obj == 'undefined' || obj === null || obj === '' || obj.value == "") return true;
            if (typeof obj == 'number' && isNaN(obj)) return true;
            if (obj instanceof Date && isNaN(Number(obj))) return true;
            return false;
        }

        function IsValidDateFormat(sText) {
            var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;
            return reDate.test(sText);
        }

        function ValidateHourMinute() {
           

            var stDts = false;
            var endDts = false;
            var endDtsgt = false;

            var stDt = document.getElementById('<%= dtActStDate.Controls[0].ClientID %>');
            var endDt = document.getElementById('<%= dtActEndDate.Controls[0].ClientID %>');

            var startDateHour = document.getElementById("<%=dtActStDate.Controls[1].ClientID %>").value; // gets value from hours dropdown list for 1st datetime control
            var startDateMinute = document.getElementById("<%=dtActStDate.Controls[2].ClientID %>").value; // gets value from minutes dropdown list for 1st datetime control
            var timeStart = new Date();
            var timeEnd = new Date();
            var strStartHour;
            var hourType;


            if (isEmpty(stDt)) {
                alert('The Start Date cannot be left blank');
                stDt.focus();
                return false;
            }
            else {
                if (!IsValidDateFormat(stDt.value)) {
                    alert('Date format should be dd/mm/yyyy');
                    stDt.focus();
                    return false;
                }
                else {
                    stDts = true;
                }
            }

            if (stDts) {

                if (isEmpty(endDt)) {
                    alert('The End Date cannot be left blank');
                    endDt.focus();
                    return false;
                }
                else {
                    if (!IsValidDateFormat(endDt.value)) {
                        alert('Date format should be dd/mm/yyyy');
                        endDt.focus();
                        return false;
                    }
                    else {

                        if (!PreSaveAction(stDt, endDt)) {
                            alert('The End Date Time cannot be earlier than the Start Date Time');
                            endDt.focus();
                            return false;
                        }
                        else {
                            endDts = true;
                        }
                    }
                }

            }

            function PreSaveAction(travelDt, returnDt) {
                var date1 = travelDt;
                var date2 = returnDt;
                var arrDate1 = date1.value.split("/");
                var useDate1 = new Date(arrDate1[2], arrDate1[1] - 1, arrDate1[0]);

                var arrDate2 = date2.value.split("/");
                var useDate2 = new Date(arrDate2[2], arrDate2[1] - 1, arrDate2[0]);
                if (useDate1 > useDate2) {
                    return false;
                }
                else if (useDate1 < useDate2) {
                return true;
                }
                else {
                    endDtsgt = true;
                }
                return true;
            }

            if (endDtsgt == true) {

                hourType = startDateHour.split(' ');
                if (hourType[1] == "AM") {
                    startDateHour = startDateHour.split(' ');
                    strStartHour = startDateHour[0];
                }
                else {
                    startDateHour = startDateHour.split(' ');
                    strStartHour = startDateHour[0];
                    strStartHour = parseInt(strStartHour) + 12;
                }
                timeStart.setHours(strStartHour, startDateMinute, 0, 0);
                var strEndHour;
                var endDateHour = document.getElementById("<%=dtActEndDate.Controls[1].ClientID %>").value; // gets value from hours dropdown list for 2nd datetime control
                var endDateMinute = document.getElementById("<%=dtActEndDate.Controls[2].ClientID %>").value; // gets value from minutes dropdown list for 2nd datetime control
                hourType = endDateHour.split(' ');
                if (hourType[1] == "AM") {
                    endDateHour = endDateHour.split(' ');
                    strEndHour = endDateHour[0];
                }
                else {
                    endDateHour = endDateHour.split(' ');
                    strEndHour = endDateHour[0];
                    strEndHour = parseInt(strEndHour) + 12;
                }
                timeEnd.setHours(strEndHour, endDateMinute, 0, 0);
                if (timeStart >= timeEnd) {
                    alert('The End Date Time cannot be earlier than the Start Date Time');
                    return false;

                }
                else {
                    return true;
                }
            }
        }

    </script>
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    Opportunity Action(s)
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
    Opportunity Action(s)
</asp:Content>
